package com.example.twitter;

import twitter4j.auth.AccessToken;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class CrearTweet extends Activity implements OnClickListener{
	Button boton;
	ConfiguracionTwitter config;
	EditText et;
	
	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.crear_tweet);
		boton = (Button) this.findViewById(R.id.botonEnviar);
		boton.setOnClickListener(this);
		et = (EditText) this.findViewById(R.id.textViewTweet);
		config = new ConfiguracionTwitter(this);
		SharedPreferences prefs = this.getSharedPreferences("MySettingsTwitter", 0);
		config.token = prefs.getString("token", "");
		config.tokenSecret = prefs.getString("tokenSecret", "");
		config.accessToken = new AccessToken(config.token, config.tokenSecret);
		
		config.twitter.setOAuthAccessToken(config.accessToken);
		
	}

	@Override
	public void onClick(View v) {
		Toast toast = null;
		if(config.PublicarTweet(et.getText().toString())){
			this.setResult(RESULT_OK);
		}
		else{
			this.setResult(RESULT_FIRST_USER);
			Intent t = this.getIntent();
			t.putExtra("resultado", false);
		}
	
			
		finish();
		
	}
	
	
}
